package com.hndzyu.yd.my;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.gyf.barlibrary.ImmersionBar;
import com.hndzyu.yd.R;
import com.hndzyu.yd.bean.TiBean;
import com.hndzyu.yd.bean.UserBean;
import com.hndzyu.yd.url.Path;
import com.hndzyu.yd.utils.OkHttpDownloadJsonUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TiRecordActivity extends AppCompatActivity {

    @BindView(R.id.top_back)
    ImageButton topBack;
    @BindView(R.id.top_title)
    TextView topTitle;
    @BindView(R.id.recycler)
    RecyclerView recycler;
    private TiRecordAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ti_record);
        ButterKnife.bind(this);
        ImmersionBar.with(this)
                .fitsSystemWindows(true)  //使用该属性,必须指定状态栏颜色
                .statusBarColor(R.color.white)
                .statusBarDarkFont(true, 0.2f)
                .init();
        topTitle.setText("提现记录");
        initData();
        setListener();
    }

    private void initData(){
        recycler.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new TiRecordAdapter(TiRecordActivity.this);
        recycler.setAdapter(mAdapter);
        tiXianList(UserBean.uid);
    }

    private void setListener() {
        topBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
    private void tiXianList(int uid){
        OkHttpDownloadJsonUtil.downloadJson(TiRecordActivity.this, Path.successTixian + "?type=1&uid=" + uid, new OkHttpDownloadJsonUtil.onOkHttpDownloadListener() {
            @Override
            public void onsendJson(String json) {
                if (!"1".equals(json) && !"2".equals(json)){
                    Gson gson = new Gson();
                    TiBean tiBean = gson.fromJson(json, TiBean.class);
                    if (tiBean.getData().size()>0){
                        mAdapter.updateData(tiBean.getData());
                    } else {
                        Toast.makeText(TiRecordActivity.this, "暂无提现记录", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        ImmersionBar.with(this).destroy();
    }
}
